<h3>Minichat</h3>
<?php

require_once('config.php');
$pseudo = mysql_real_escape_string(htmlspecialchars ($_POST['pseudo_chat']));
$message = mysql_real_escape_string(htmlspecialchars($_POST['message_chat']));

if($pseudo != "" AND $message != "")
{
	$reponse = mysql_query("SELECT id, message FROM minichat_skyblog ORDER BY id DESC LIMIT 0, 1") or die(mysql_error());
	$donnees = mysql_fetch_array($reponse);
	if (stripslashes($message) == $donnees['message'])
	{
		echo "<p><strong>Pas de doublon, merci.</strong></p>";
	}
	else
	{
	$date = time();
	$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
	mysql_query("INSERT INTO minichat_skyblog VALUES('', '$pseudo', '$message', '$date', '$ip')") or die(mysql_error());
	echo "<p><strong>Message envoyé !</strong></p>";
	}
}

elseif($pseudo != "" OR $message != "")
{
	echo "<p>Merci de remplir tous les champs !</p>";
}

echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="post"><p>';
echo 'Pseudo : <input type="text" name="pseudo_chat" size="20" value="'.$pseudo.'" /><br />';
echo 'Message :<br /><textarea name="message_chat" cols="40" rows="5"></textarea><br />';
echo '<input type="submit" value="Envoyer" /></p></form>';

$reponse = mysql_query("SELECT * FROM minichat_skyblog ORDER BY id DESC LIMIT 0, 10") or die(mysql_error());
while ($donnees = mysql_fetch_array($reponse) )
{
$message = stripslashes(nl2br($donnees['message']));
	if($donnees['pseudo'] == "Ced")
	{
		echo '<p><span class="admin"><strong>'.$donnees['pseudo'].'</strong></span> (envoyé le '.date('d/m à H:i', $donnees['date']).') :<br />'.$message.'</p>';
	}
	else{
	echo '<p><strong>'.$donnees['pseudo'].'</strong> (envoyé le '.date('d/m à H:i', $donnees['date']).') :<br />'.$message.'</p>';
	}
}
 
 ?>